package com.zl.gmadmin.service.dto;

import com.zl.gmadmin.entity.SysMenu;
import com.zl.gmadmin.utils.Builder;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author zhangliang
 * @version 1.0
 * @date 2021/2/7 17:21
 */
public class MenuDto extends BaseDTO implements Serializable {
    private Long id;

    private List<MenuDto> children;

    private Integer type;

    private String permission;

    private String title;

    private Long menuSort;

    private String path;

    private String component;

    private Long pid;

    private Integer subCount;

    private Boolean iFrame;

    private Boolean cache;

    private Boolean hidden;

    private String componentName;

    private String icon;

    private String Method;


    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        MenuDto menuDto = (MenuDto) o;
        return Objects.equals(id, menuDto.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }


    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public List<MenuDto> getChildren() {
        return children;
    }

    public void setChildren(List<MenuDto> children) {
        this.children = children;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public String getPermission() {
        return permission;
    }

    public void setPermission(String permission) {
        this.permission = permission;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public Long getMenuSort() {
        return menuSort;
    }

    public void setMenuSort(Long menuSort) {
        this.menuSort = menuSort;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public String getComponent() {
        return component;
    }

    public void setComponent(String component) {
        this.component = component;
    }

    public Long getPid() {
        return pid;
    }

    public void setPid(Long pid) {
        this.pid = pid;
    }

    public Integer getSubCount() {
        return subCount;
    }

    public void setSubCount(Integer subCount) {
        this.subCount = subCount;
    }

    public Boolean getiFrame() {
        return iFrame;
    }

    public void setiFrame(Boolean iFrame) {
        this.iFrame = iFrame;
    }

    public Boolean getCache() {
        return cache;
    }

    public void setCache(Boolean cache) {
        this.cache = cache;
    }

    public Boolean getHidden() {
        return hidden;
    }

    public void setHidden(Boolean hidden) {
        this.hidden = hidden;
    }

    public String getComponentName() {
        return componentName;
    }

    public void setComponentName(String componentName) {
        this.componentName = componentName;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public MenuDto() {
        super();
    }

    public MenuDto(Long id, List<MenuDto> children, Integer type, String permission, String title, Long menuSort, String path, String component, Long pid, Integer subCount, Boolean iFrame, Boolean cache, Boolean hidden, String componentName, String icon) {
        super();
        this.id = id;
        this.children = children;
        this.type = type;
        this.permission = permission;
        this.title = title;
        this.menuSort = menuSort;
        this.path = path;
        this.component = component;
        this.pid = pid;
        this.subCount = subCount;
        this.iFrame = iFrame;
        this.cache = cache;
        this.hidden = hidden;
        this.componentName = componentName;
        this.icon = icon;
    }

//    public static List<MenuDto> buildList(List<SysMenu> sysMenus) {
//        List<MenuDto> menuDtoList=new ArrayList<>();
//        sysMenus.forEach(sysMenu -> {
//            MenuDto menuDto= Builder.of(MenuDto::new)
//                    .with(MenuDto::setId,sysMenu.getMenuId())
//                    .with(MenuDto::setType,sysMenu.getType())
//                    .with(MenuDto::setPermission,sysMenu.getPermission())
//                    .with(MenuDto::setTitle,sysMenu.getTitle())
//                    .with(MenuDto::setMenuSort,sysMenu.getMenuSort())
//                    .with(MenuDto::setPath,sysMenu.getPath())
//                    .with(MenuDto::setComponent,sysMenu.getComponent())
//                    .with(MenuDto::setPid,sysMenu.getPid())
//                    .with(MenuDto::setSubCount,sysMenu.getSubCount())
//                    .with(MenuDto::setiFrame,sysMenu.getiFrame().equals("0")?false:true)
//                    .with(MenuDto::setCache,sysMenu.getCache().equals("0")?false:true)
//                    .with(MenuDto::setHidden,sysMenu.getHidden().equals("0")?false:true)
//                    .with(MenuDto::setComponentName,sysMenu.getName())
//                    .with(MenuDto::setIcon,sysMenu.getIcon())
//                    .with(MenuDto::setCreateTime,sysMenu.getCreateTime())
//                    .with(MenuDto::setCreateBy,sysMenu.getCreateBy())
//                    .with(MenuDto::setUpdatedBy,sysMenu.getUpdateBy())
//                    .with(MenuDto::setUpdateTime,sysMenu.getUpdateTime())
//                    .build();
//            menuDtoList.add(menuDto);
//        });
//        return menuDtoList;
//    }

    public String getMethod() {
        return Method;
    }

    public void setMethod(String method) {
        Method = method;
    }

    public static MenuDto buildMenuDto(SysMenu sysMenu) {
        MenuDto menuDto = Builder.of(MenuDto::new)
                .with(MenuDto::setId, sysMenu.getId())
                .with(MenuDto::setType, sysMenu.getType())
                .with(MenuDto::setPermission, sysMenu.getPermission())
                .with(MenuDto::setTitle, sysMenu.getTitle())
                .with(MenuDto::setMenuSort, sysMenu.getMenuSort())
                .with(MenuDto::setPath, sysMenu.getPath())
                .with(MenuDto::setComponent, sysMenu.getComponent())
                .with(MenuDto::setPid, sysMenu.getPid())
                .with(MenuDto::setSubCount, sysMenu.getSubCount())
                .with(MenuDto::setiFrame, sysMenu.getiFrame())
                .with(MenuDto::setCache, sysMenu.getCache())
                .with(MenuDto::setHidden, sysMenu.getHidden())
                .with(MenuDto::setComponentName, sysMenu.getName())
                .with(MenuDto::setIcon, sysMenu.getIcon())
                .with(MenuDto::setCreateTime, sysMenu.getCreateTime())
                .with(MenuDto::setCreateBy, sysMenu.getCreateBy())
                .with(MenuDto::setUpdatedBy, sysMenu.getUpdateBy())
                .with(MenuDto::setUpdateTime, sysMenu.getUpdateTime())
                .with(MenuDto::setMethod, sysMenu.getMethod())
                .build();

        return menuDto;
    }
}
